<?php
    $xtpl_soft      = new XTemplate("view/product/soft.htm");
    
    $heading    = "Các sản phẩm";
    $soft       = $_GET['s'];
    $offset     = $_GET['p'];
    $limit      = 6;
    $offset     = (isset($offset) && ($offset > 0)) ? $offset : 0;
    
    switch($soft){
        case    '1'     : $sql_soft = "cost < 10"; break;
        case    '2'     : $sql_soft = "cost >= 10 AND cost <= 100"; break;
        case    '3'     : $sql_soft = "cost >= 100 AND cost <= 300"; break;
        case    '4'     : $sql_soft = "cost > 300"; break;
    }
    
    $query          = "SELECT count(*) AS totalRecords FROM product WHERE " . $sql_soft;
    $re             = mysql_query($query);
    $rows           = mysql_fetch_assoc($re);
    $totalRecords   = $rows['totalRecords'];
    
    $pages  = pagging($totalRecords, $offset, $limit, '?page=milk&module=' . $module . '&s=' . $soft);
    $sql    = "SELECT * FROM product WHERE " . $sql_soft . " ORDER BY cost ASC LIMIT " . $offset . ", " . $limit . "";
    $result = mysql_query($sql);        
    while($row = mysql_fetch_array($result)){
        $xtpl_soft  -> assign('id1', $row['id_p']);
        $xtpl_soft  -> assign('id2', $row['id_p']);
        $xtpl_soft  -> assign('image', $row['image']);
        $xtpl_soft  -> assign('milkname', $row['milkname']);
        $xtpl_soft  -> assign('cost', $row['cost']);
        $xtpl_soft  -> assign('id3', $row['id_p']);
        $xtpl_soft  -> insert_loop('SOFT.TABLES', array('LIST'=>$row));
    }
    
    $xtpl_soft  -> assign('pages', $pages);
    $xtpl_soft  -> assign('heading', $heading);  
    $xtpl_soft      -> parse("SOFT");
    $mid            = $xtpl_soft -> text("SOFT");
?>